package com.siloam.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.siloam.module.User;
import com.siloam.service.UserService;
import com.siloam.vo.PageParam;
import com.siloam.vo.PageVO;
import com.siloam.vo.UserVO;

@Controller
@RequestMapping("/web/user/user.do")
public class UserController extends BaseController{

	@Resource
	private UserService userService;
	
	@RequestMapping(params="method=add")
	@ResponseBody
	public String add(User user){
		userService.add(user);
		return SUCCESS;
	}
	
	@RequestMapping(params="method=initEdit")
	public String initEdit(int id,ModelMap map){
		User user = userService.load(id);
		map.put("user", user);
		return "/web/user/editUser";
	}
	
	@RequestMapping(params="method=update")
	@ResponseBody
	public String saveEdit(User user){
		User u = userService.load(user.getId() );
		u.setName(user.getName());
		u.setQq(user.getQq());
		userService.update(u);
		return SUCCESS;
	}
	
	@RequestMapping(params="method=delSome")
	@ResponseBody
	public String delete(String ids){
		userService.delete(ids);
		return SUCCESS;
	}
	
	@RequestMapping(params="method=listUser")
	@ResponseBody
	public PageVO<UserVO> listUser(PageParam param){
		return userService.findPage(param.getRowBeginIndex(), param.getRowCount() );
	}
	
	@RequestMapping(params="method=setStatus")
	@ResponseBody
	public String setStatus(String ids, int status){
		userService.setStatus(ids, status);
		return SUCCESS;
	}
	
	public UserService getUserService() {
		return userService;
	}

	public void setUserService(UserService userService) {
		this.userService = userService;
	}
	
	@RequestMapping(params="method=searchUser")
	@ResponseBody
	public List<User> searchUser(String name, int type){
		return userService.searchUser(name, type);
	}
	
}

